home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / util / misc / ReqAttackUpd.lha / ReqAttackUpd / ReqOFF-Bonus / reqlog.e < prev    next >
Encoding:
Text File  |  1992-07-15  |  3.2 KB  |  74 lines

  1. /* Example request saver. This program is very simple and should probably be
  2.    made more OS compatible (I mean the ReadArgs() function).
  3.  
  4.    IMPORTANT: To protect ReqOFF againts going into infinitive loop (when your
  5.    requester replacer calls EasyRequestArgs() with same TITLE and/or TEXT
  6.    as the original requester) you should add a single space as a first byte
  7.    of title string, or simply change it to other title which will not qualify
  8.    to be patched by your program again and again and again...
  9.  
  10.    IMPORTANT: In 'replacerdata' structure you receive not only the easystruc,
  11.    but also the screen pointer, idcmp and args with which the main
  12.    EasyRequestArgs was called. The 1st thing is that is not guaranteed that the
  13.    screen is still opened (I think it's better to call EasyRequestArgs() with
  14.    a NIL/NULL screen pointer because all users probably use DefaultPubScreen
  15.    patches). The 2nd is that idcmp and args may be passed incorrectly by
  16.    ReqOFF/other software (???) because mine programs hanged with these args
  17.    passed to EasyRequestArgs - so don't use them!
  18. */
  19.  
  20. MODULE 'dos/dos','other/replacer','intuition/intuition'
  21.  
  22. DEF pos,newtitle:PTR TO LONG,exit=0,fh,file[101]:STRING
  23. DEF re:PTR TO replacerdata
  24.  
  25. PROC main()
  26.   IF StrCmp(arg,'"',1)                ->  the 1st arg is log file name
  27.     pos:=InStr(arg,'"',1)             ->  which has to be specified in
  28.     StrCopy(file,arg+1,pos-1)         ->  RAPrefsMUI
  29.   ELSE
  30.     pos:=InStr(arg,' ',1)
  31.     StrCopy(file,arg,pos)             ->  now the file variable contains
  32.   ENDIF                               ->  the file name (without quotas)
  33.  
  34.  
  35.   pos:=InStr(arg,'0x',0)              ->  replace all 0x with ' $'
  36.   arg[pos]:=$20;arg[pos+1]:=$24       ->  Val() needs hexadecimal numbers...
  37.   re:=Val(arg+pos,0)                  ->  (get the value)
  38.                                       ->  ...to be preceded by '$'
  39.  
  40.   IF newtitle:=New(StrLen(re.easystr.title)+2)->  title MUST be preceded by a space
  41.                                       ->  we do not want an infinitive loop!
  42.     StringF(newtitle,' \s',re.easystr.title)
  43.                                       ->  now call the requester...
  44.     exit:=EasyRequestArgs(0,[20,0,newtitle,re.easystr.textformat,re.easystr.gadgetformat],0,0)
  45.                                       ->  and add info to the log file...
  46.     IF fh:=Open(file,MODE_READWRITE)
  47.       Seek(fh,0,OFFSET_END)           ->  skip to EOF
  48.  
  49. /* Now we dont need the file name anymore, so we can use it to prepare
  50.    the text to write in log file... */
  51.  
  52.         MidStr(file,re.easystr.title,0,20);StringF(file,'TITLE:\s ',file);
  53.         Fputs(fh,file)                ->  write the title...
  54.  
  55.         MidStr(file,re.easystr.textformat,0,30);StringF(file,'TEXT:\s ',file);
  56.         removenextline();Fputs(fh,file)->  write the text...
  57.  
  58.         MidStr(file,re.easystr.gadgetformat,0,15);StringF(file,'BUTT:\s EXIT:\d\n',file,exit);
  59.         Fputs(fh,file)->  write the button info and exit #...
  60.  
  61.       Close(fh)
  62.     ENDIF
  63.   ENDIF
  64. ENDPROC exit
  65.  
  66. /* This procedure checks all bytes in string for $0a (next line) and replaces
  67.    it with $20 - space */
  68. PROC removenextline()
  69. DEF no
  70.   FOR no:=0 TO StrLen(file)
  71.     IF file[no]=$0a;file[no]:=$20;ENDIF
  72.   ENDFOR
  73. ENDPROC
  74.